package com.bnyy.medicalHousekeeper.request;

import android.app.ProgressDialog;
import android.content.Context;

import org.xutils.common.Callback;

/**
 * Author : 关炳鹏
 * Description :
 * Date : 2022/6/9
 **/
public abstract class XUtilsRequestCallback implements Callback.CommonCallback<String> {

    private ProgressDialog progressDialog;

    public XUtilsRequestCallback() {
    }

    public XUtilsRequestCallback(Context context) {
        if (context != null) {
            progressDialog = ProgressDialog.show(context, "", "正在获取数据，请稍后");
        }
    }

    @Override
    public void onSuccess(String result) {
        dismissDialog();
    }

    @Override
    public void onError(Throwable ex, boolean isOnCallback) {
        dismissDialog();
    }

    @Override
    public void onCancelled(CancelledException cex) {
        dismissDialog();
    }

    @Override
    public void onFinished() {
        dismissDialog();
    }

    private void dismissDialog() {
        if (progressDialog != null && progressDialog.isShowing()) {
            progressDialog.dismiss();
            progressDialog = null;
        }
    }
}
